import { useLocation } from 'react-router-dom';

const useRouteQuery = ({ key }: { key?: string }) => {
  const query = function useQuery() {
    // return new URLSearchParams(window.location.search);
    return new URLSearchParams(useLocation().search);
  };

  const get = () => {
    if (!key) {
      return query();
    }
    return query()?.get(key);
  };

  return get();
};

export default useRouteQuery;
